home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 1 / MF_UK_160_1.iso / pc / DiscContent / FullSoftware / Amapi61MacEn / Amapi 3D 6.1 Installer / 3SPACE / PressBehavior.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  2.2 KB  |  88 lines  |  [AMAS/AMAP]

  1. // -* PressBehavior.js *-
  2. //
  3. // Name: Press behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: PressBehavior.js,v 1.6 2000/12/21 15:03:30 consumer Exp $
  7. //
  8. var gDataTable = new Array(1);
  9.  
  10. function PressBehaviorInit(solidName, axis, stiffness, damping)
  11. {
  12.   // Make a new solid for attaching the cylindrical link and the spring
  13.   var handleId = TSMakeUniqID("PressAttach_" + solidName);
  14.   gDataTable[solidName] = handleId;
  15.  
  16.   TSMakeSolid(handleId, '1', TSSolidGetPosition(solidName));
  17.  
  18.   var springId = TSMakeUniqID("SpringForce_" + solidName)
  19.  
  20.   TSMakeSpringForce(springId,
  21.             stiffness,
  22.             damping,
  23.             '0 0 0',
  24.             solidName);
  25.  
  26.   var linkId = TSMakeUniqID("CylindricalLink_" + solidName);
  27.  
  28.   var position = TSGetAttribute(solidName,'position');
  29.   TSMakeCylindricalLink(linkId,axis,position,solidName);
  30.  
  31.   // Build the hierarchy
  32.   TSAppendChild(handleId, linkId);
  33.   TSAppendChild(handleId, springId);
  34.   TSAppendChild(TSGetSceneId(), handleId);
  35.   TSUpdateNode(handleId);
  36.  
  37.   // Free the solid
  38.   TSUpdateNodeAttribute(solidName, 'fixed', '0');
  39. }    
  40.  
  41. function PressBehaviorKill(solidName)
  42. {
  43. }
  44.  
  45. function PressBehaviorStart(solidName, direction, intensity)
  46. {
  47.   var position  = TSSolidGetPosition(solidName);
  48.   var dampingId = TSMakeUniqID("DampingForce_" + solidName);
  49.   var shootId   = TSMakeUniqID("ShootForce_" + solidName);
  50.     
  51.   TSMakeDampingSolidForce(dampingId, 0.5, 0.5)
  52.   TSAppendChild(solidName, dampingId);
  53.  
  54.   direction = TSMakeStringFromPoint(TSPointNegate(TSMakePointFromString(direction)));
  55.  
  56.   TSMakeShootForce(shootId, direction, intensity, TSMakeStringFromPoint(position));
  57.   TSAppendChild(solidName, shootId);
  58.   TSUpdateNode(shootId);
  59.   TSRemoveNode(shootId);
  60.   TSRemoveNode(dampingId);
  61. }
  62.  
  63. function PressBehaviorStop(solidName)
  64. {
  65. }
  66.  
  67. //
  68. // Event functions
  69. //
  70.  
  71. function PressBehaviorStartEvent(obj, event)
  72. {
  73.   var axis      = TSGetExtraParam(event, 'axis');
  74.   var intensity = TSGetExtraParam(event, 'intensity');
  75.   var stiffness = TSGetExtraParam(event, 'stiffness');
  76.   var damping   = TSGetExtraParam(event, 'damping');
  77.  
  78.   if (gDataTable[obj] == null) {
  79.     PressBehaviorInit(obj, axis, stiffness, damping);
  80.   }
  81.  
  82.   PressBehaviorStart(obj, axis, intensity);
  83. }
  84.  
  85. function PressBehaviorStopEvent(obj, event)
  86. {
  87. }
  88.